home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / SAT 2.3.7 / Add-ons / Lib ƒ / SATAddOnLib.p < prev   
Encoding:
Text File  |  1995-11-08  |  5.8 KB  |  142 lines  |  [TEXT/PJMM]

  1. {SATAddOnLib is a lib of the "Add-ons" that are easily put in a library (i.e. the ones without}
  2. {a "stubs" file). They include:}
  3. {}
  4. {GammaFade}
  5. {ProgressBar}
  6. {FaceFromPict}
  7. {SATToolbox}
  8. {Preferences}
  9.  
  10. unit SATAddOnLib;
  11. interface
  12.     uses
  13.         SAT;
  14.  
  15. {*** GammaFade ***}
  16. {Screen fading routines.}
  17.  
  18.     procedure FadeToBlack (ticks: Longint);
  19.     procedure FadeFromBlack (ticks: Longint);
  20.  
  21. {*** FaceFromPict ***}
  22. {Load a face from PICTs}
  23.  
  24.     function GetFaceFromPICT (colorPICTid, bwPICTid, maskPICTid: integer): FacePtr;
  25.  
  26. {Pixel array types and routines}
  27.     type
  28.         Pixel = record
  29.                 position: Point;
  30.                 data1, data2, data3, data4: SignedByte;
  31.             end;
  32.         Pixels = array[0..32000] of Pixel;
  33.         PixelPtr = ^Pixels;
  34.  
  35.     procedure SATDrawPixels (pix: PixelPtr; var port: SATPort; value: Longint);
  36.     procedure SATCopyPixels (pix: PixelPtr; var src, dest: SATPort);
  37.     procedure SATDrawPixelsSafe (pix: PixelPtr; var port: SATPort; value: Longint);
  38.     procedure SATCopyPixelsSafe (pix: PixelPtr; var src, dest: SATPort);
  39.  
  40. {*** Preferences ***}
  41. {Create a preference file in the Preferences folder.}
  42.  
  43. {Open the pref file if needed. Return the variables appFile and prefFile.}
  44. {If alwaysExternal is true, we always want a pref file in the system folder even if we can save in the application.}
  45. {Returns true if a new prefFile was created.}
  46.     function SetPrefFile (prefsFileName: Str255; prefCreator, prefType: OSType; var appFile, prefFile: Integer; alwaysExternal: Boolean): Boolean;
  47.  
  48. {Copy a resource from one file to another. Useful when SetPrefFile returns true!}
  49.     function CopyResource (fromFile, toFile: integer; theResType: ResType; id: integer): OSErr;
  50.  
  51. {*** ProgressBar ***}
  52. {An adaptive progress bar, adjusts itself automatically by remembering how much time the}
  53. {time-consuming operation took last time.}
  54.  
  55. {Note: The full type declarations are removed to make this brief. See ProgressBar.p if you need them.}
  56.     type
  57.         ProgressBarColorPtr = Ptr;
  58.         ProgressBarPtr = Ptr;
  59.  
  60.     function InitProgressBar (prefFile, resID: Integer; bounds: Rect; colors: ProgressBarColorPtr): ProgressBarPtr;
  61.     function ProgressBarColors (frameRed, frameGreen, frameBlue, backRed, backGreen, backBlue, foreRed, foreGreen, foreBlue: Integer): ProgressBarColorPtr;
  62.     function ProgressBarColorsRGB (frame, back, fore: RGBColor): ProgressBarColorPtr;
  63.     procedure AdvanceProgressBar (thePB: ProgressBarPtr);
  64.     procedure FinishProgressBar (thePB: ProgressBarPtr);
  65.  
  66. {*** SATToolbox ***}
  67. {Some sprite handling routines, plus some math routines.}
  68.  
  69. {The following switch should be true if your SAT.p has a fixedPointPosition field.}
  70. {MUST MATCH THE FLAG IN SATToolbox.p WHEN THE LIB WAS COMPILED!}
  71. {$setc _hasfixedpoint = true}
  72.  
  73.     type
  74.         FixSpritePtr = ^FixSprite;
  75.         FixSprite = record
  76. { Variables that you should change as appropriate }
  77.                 kind: Integer; { Used for identification. >0: friend. <0 foe }
  78.                 position: Point;
  79.                 hotRect, hotRect2: Rect; { Tells how large the sprite is; hotRect is centered around origo }
  80.                                     {hotRect is set by you. hotRect2 is offset to the current position.}
  81.                 face: FacePtr;            { Pointer to the Face (appearance) to be used. }
  82.                 task: ProcPtr;            { Callback-routine, called once per frame. If task=nil, the sprite is removed. }
  83.                 hitTask: ProcPtr;        { Callback in collisions. }
  84.                 destructTask: ProcPtr;    { Called when a sprite is disposed. (Usually nil.) }
  85.                 clip: RgnHandle;            {Clip region to be used when this sprite is drawn.}
  86. { SAT variables that you shouldn't change: }
  87.                 oldpos: Point;                {Used by RunSAT2}
  88.                 next, prev: SpritePtr;    {You may change them in your own sorting routine, but be careful if you do.}
  89.                 r, oldr: Rect;                {Rectangle telling where to draw. Avoid messing with it.}
  90.                 oldFace: FacePtr;            {Used by RunSAT2}
  91.                 dirty: Boolean;            {Used by RunSAT2}
  92. {Variables for internal use by the sprites. Use as you please. Edit as necessary - this is merely a default}
  93. {set, enough space for most cases - but if you change the size of the record, call SetSpriteSize immediately}
  94. {after initializing (before any sprites are created)!}
  95.                 layer: integer; {For layer-sorting. When not used for that, use freely.}
  96.                 speed: Point; { Can be used for speed, but not necessarily. }
  97.                 mode: integer; { Usually used for different modes and/or to determine what image to show next. }
  98.                 fixedPointPosition: Point; {fixed point position}
  99.                 appLong: Longint; {Longint for free use by the application.}
  100.             end;
  101.  
  102. {Constants for separation/bounceoff between sprites}
  103.     const
  104.         kPushBoth = 0;
  105.         kPushMe = 1;
  106.         kPushHim = 2;
  107.  
  108. (*Sprite utilities*)
  109.     procedure MoveSprite (theSprite: SpritePtr);
  110.     function KeepOnScreen (theSprite: SpritePtr): Boolean;
  111. {$ifc _hasfixedpoint}
  112.     procedure MoveSpriteFixedPoint (theSprite: FixSpritePtr);
  113.     function KeepOnScreenFixed (theSprite: FixSpritePtr): Boolean;
  114. {$endc}
  115.     function RectSeparate (theSprite: SpritePtr; anotherSprite: SpritePtr; push: Integer): Integer;
  116.     procedure RectBounce (me, him: SpritePtr; push: Integer);
  117.     procedure RectBounceFixed (me, him: FixSpritePtr; push: Integer);
  118.     function PtInSpriteRgn (p: Point; theSprite: SpritePtr): Boolean;
  119.     function RegionHit (theSprite: SpritePtr; anotherSprite: SpritePtr): Boolean;
  120.     procedure SplitVector (v: Point; d: Point; var p: Point; var n: Point);
  121.  
  122.     procedure RegionBounce (s1, s2: FixSpritePtr);
  123.  
  124. {*** Look-up table based fixed-point math operations. ***}
  125. {Good for high-speed trig functions on 68k Macs. (Not tested too much yet.)}
  126.  
  127. {Don't change these constants without recompiling the lib!}
  128.     const
  129.         kFixedPointShift = 4; {Number of fixed-point positions}
  130.         kFixedOne = 16; {The "one" in the fixed-point system being used!}
  131.  
  132.     procedure InitTables; {Init not required}
  133.     function SquareRoot (arg: Longint): Longint;
  134.     function Sinus (arg: Longint): Longint;
  135.     function Cosinus (arg: Longint): Longint;
  136.     function VectorLength (vector: Point): Longint;
  137.     function FPVectorLength (vector: Point): Longint;
  138.  
  139.  
  140.  
  141. implementation
  142. end.